﻿using AutoMapper;
using Durian.API.Application.Commands.Assembly;
using IMES.Common.Domain.DurianModel;
using IMES.Common.Dtos;
using IMES.Common.Infrastructure;
using MediatR;

namespace Durian.API.Application.Commands.Mission
{
    public class MissionUntilHandler : IRequestHandler<MissionUntilCommand, ResultT<Tasks>>
    {
        private readonly IMapper mapper;
        private readonly ILogger<MissionSelectHandler> logger;
        private readonly IBaseRepositorys<ProcessManagement> processManagementRepository;
        private readonly IBaseRepositorys<Tasks> tasksRepository;

        public MissionUntilHandler(IMapper mapper, ILogger<MissionSelectHandler> logger, IBaseRepositorys<ProcessManagement> processManagementRepository, IBaseRepositorys<Tasks> tasksRepository)
        {
            this.mapper = mapper;
            this.logger = logger;
            this.processManagementRepository = processManagementRepository;
            this.tasksRepository = tasksRepository;
        }

        /// <summary>
        /// 反填任务信息方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<ResultT<Tasks>> Handle(MissionUntilCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<Tasks>();
                result.Item = tasksRepository.GetAll().FirstOrDefault(c => c.TasksId == request.TasksId);
                logger.LogInformation("反填任务信息方法调用成功");
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("反填任务信息方法出错" + ex);
                throw;
            }
        }
    }
}
